import it.randomtower.engine.World;

import java.util.ArrayList;

import org.newdawn.slick.Animation;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.tiled.TiledMap;


/**
 * 
 * movement based on location on grid
 * players are in the PlayerSelect java
 *
 */
public class GamePlayerSelect extends World {
	//private float playerX = 320;
	//private float playerY = 240;
	private TiledMap map;
	private ArrayList<PlayerSelect> players = new ArrayList<PlayerSelect>();
	

	public GamePlayerSelect(int id, GameContainer container) {
		super(id, container);
		
	}
	
	public GamePlayerSelect(int id) throws SlickException{
		super(id);
		map = new TiledMap("images/simplelevel.tmx");
		PlayerSelect player1 = new PlayerSelect(0,0);
		players.add(player1);
		players.add(new PlayerSelect(32,32));
		add(player1);
	}

	
	public void update(GameContainer container, int delta) {
		Input input = container.getInput();
		int mouseX = input.getMouseX();
		int mouseY = input.getMouseY();
		boolean mousePressed = false;

		if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) && mousePressed == false) {
			mousePressed = true;
		}

		if (mousePressed == true) {
			for(int i = 0; i < players.size() -1; i++){
				if(players.get(i).isPlayerAtLocation(mouseX, mouseY))
					players.get(i).movePlayer(container, players);
			}
			
		}
		
	}

	public void render(GameContainer container, Graphics g) {
		map.render(0, 0);
		for(PlayerSelect player:players){
			try {
				player.render(container, g);
			} catch (SlickException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}

	
}
/*
//Find a path between you and the pixel coordinate target "target" 
public void setTarget(Vector2f target) 
     { 
         this.target = target; 
         fitTargettoGrid(); 
         findPath(); 
         currentStep=0; 
     } 

//Convert pixel coordinates of "target" to grid coordinates. 
public void fitTargettoGrid() 
     { 
    int currentTileX=(int) (target.x/Game.currentMap.getTileWidth()); 
      int currentTileY=(int) (target.y/Game.currentMap.getTileHeight()); 
      target=new Vector2f(currentTileX,currentTileY); 
     } 

//Fit your own coordinates to grid coordinates. 
public void findGridPosition() 
     { 
           int currentTileX=(int) (parent.getMoveSystem().pos.x/Game.currentMap.getTileWidth()); 
      int currentTileY=(int) (parent.getMoveSystem().pos.y/Game.currentMap.getTileHeight()); 
      gridPosition=new Vector2f(currentTileX,currentTileY); 
     } 

//Find a path from you to the target. 
public void findPath() 
     {  findGridPosition(); 
    pathtoTarget=pathfinder.findPath((Mover)this, (int)gridPosition.getX(), (int)gridPosition.getY(), (int)target.getX(), (int)target.getY()); 
    if(pathtoTarget==null) 
    { 
        System.out.println("ITS NULL"); 
    } 
     } */